﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing ;
using Lxzhu.OpenGL;
namespace Tutorials{
    public class GlutEngine
    {
        public GlutEngine()
        {
            this.Title = "GlutEngine";
            this.WindowSize = new Size(800, 600);
            this.Location = new Point(200, 200);
        }
        public string Title { get; set; }
        public Size WindowSize { get; set; }
        public Point Location { get; set; }
        public void Run()
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(GlutDisplayMode.GLUT_RGBA | GlutDisplayMode.GLUT_DOUBLE);
            Glut.glutInitWindowPosition(this.Location.X, this.Location.Y);
            Glut.glutInitWindowSize(this.WindowSize.Width, this.WindowSize.Height);
            Glut.glutCreateWindow(this.Title);
            
            Glut.glutKeyboardFunc(new GlutKeyboardFunctor(OnKeyDown));           
            Glut.glutDisplayFunc(new GlutDisplayFunctor(OnDisplay));
            Glut.glutReshapeFunc(new GlutReshapeFunctor(OnResize));
            Glut.glutMouseFunc(new GlutMouseFunctor(OnMouseDownUp));
            Glut.glutSpecialFunc(new GlutKeyboardFunctor(OnSpecialKeyDown));            
            Glut.glutIdleFunc(new GlutIdleFunctor(OnIdle));
            Glut.glutMotionFunc(new GlutMotionFunctor(OnMouseMotion));
            OnInit();
            Glut.glutMainLoop();
            OnExit();
        }
        public virtual void OnInit()
        {

        }
        public virtual void OnIdle()
        {

        }
        public virtual void OnDisplay()
        {
        }
        public virtual void OnResize(int w, int h)
        {
            Gl.glViewport(0, 0, w, h);
        }
        public virtual void OnKeyDown(GlutKeyCode key, int x, int y)
        {
        }
        
        public virtual void OnSpecialKeyDown(GlutKeyCode key, int x, int y)
        {
        }
       
        public virtual void OnMouseDownUp(GlutMouseButton button, GlutButtonState state, int x, int y)
        {
        }
        public virtual void OnMouseMotion(int x, int y)
        {
        }
        public virtual void OnExit()
        {
        }
    }
}

